package tools;

import java.util.ArrayList;
import java.util.List;

import datatypes.Edge;
import datatypes.Vertex;

/**
 * Test LMT triangulation by applying Vertex orderings
 * 
 * Note: this code is still under construction.
 * Rev 6.07.2011:
 * 
 * The algorithm works actually as a BFS not DFS.
 * check if all points conneted works, Vertec re-ordering not yet.
 * 
 * @author ltune
 *
 */
public class DepthFirstSearch {
	
	/**
	 * Conttructor for DFS-check pass graph as V and E lists 
	 * 
	 * */
	public DepthFirstSearch(List<Vertex> pointList, List<Edge> edgesArray) {
		super();
		this.pointList = pointList;
		this.edgesArray = edgesArray;
	}


	/* member variables for DFS search */
	private boolean reordered;
	private boolean connected;
	private List<Vertex> pointList; // represents the grpaghs' points
	private List<Edge> edgesArray; // represents the graphs' edges
	
	/* end DFS variables */

	/* getters and setters */

	public boolean isReordered() {
		return reordered;
	}

	public void setReordered(boolean reordered) {
		this.reordered = reordered;
	}

	public List<Vertex> getPointList() {
		return pointList;
	}

	public void setPointList(List<Vertex> pointList) {
		this.pointList = pointList;
	}

	public List<Edge> getEdgesArray() {
		return edgesArray;
	}

	public void setEdgesArray(List<Edge> edgesArray) {
		this.edgesArray = edgesArray;
	}
	
	public boolean isConnected() {
		return connected;
	}

	public void setConnected(boolean connected) {
		this.connected = connected;
	}

	/* end gettes and setters */
	

	/**
	 * This is the DFS' heart, note it is not yet ready.
	 * Now, you can  ,howerver, check, whether all your points 
	 * are connected by at least one Edge or not.
	 * (ie: Whether all Point are connected at all)
	 * 
	 */
	public void search(){
		boolean c=false;// we assume points are not connected.
		checkpoint :for (int i = 0; i<pointList.size(); i++) {
			// check if all points are connected
			for (int j = 0; j < edgesArray.size(); j++) {
				if(edgesArray.get(j).getVector().getX()==pointList.get(i).getX() &&
						edgesArray.get(j).getVector().getY()==pointList.get(i).getY()){
					//point is connected to an eges so continue
					continue checkpoint;
				}
			}
			// OH NO! WE found a not connected point!
			setConnected(c);
			return;
		}
		// OK! WE have checked and all Points are connected! GOOD Work!
		c=true;
		setConnected(c);
		return;
	}
	
	/**
	 * Reorder graph when necessary.
	 * Set member reordered: true
	 */
	protected void reorder(){
		// TODO reoder the edges
		setReordered(true);
	}
}
